<?php
//已经反馈
namespace app\admin\controller;
use think\Db;
class Feedback extends Base {
    /***
     * 首页
     */
    public function index(){
        if(request()->isAjax()){
            extract(input());
            $map =array();
            $page = input('page') ? input('page'):1;
            $limit = input("limit")?input("limit"):10;// 获取总条数;
            if(isset($key)&&$key!="")
            {
                $map['uuu.user_username|uuu.user_phone'] = ['like',"%" . $key . "%"];
            }
            if(isset($start)&&$start!=""&&isset($end)&&$end=="")
            {
                $map['a.feedback_time'] = ['>= time',$start];
            }
            if(isset($end)&&$end!=""&&isset($start)&&$start=="")
            {
                $map['a.feedback_time'] = ['<= time',$end];
            }
            if(isset($start)&&$start!=""&&isset($end)&&$end!="")
            {
                $map['a.feedback_time'] = ['between time',[$start,$end]];
            }
            $count = Db::table('up_feedback')->alias('a')
                ->join('up_u_user uuu','uuu.user_id = a.user_id','left')
                ->where($map)
                ->count();
            $list = Db::table('up_feedback')->alias('a')
                ->join('up_u_user uuu','uuu.user_id = a.user_id','left')
                ->where($map)
                ->field('a.*,uuu.user_username,uuu.user_phone')
                ->order('a.feedback_status asc,a.feedback_time desc')
                ->page($page, $limit)
                ->select();//计算总页面
            return json(['code'=>0,'msg'=>'','count'=>$count,'data'=>$list]);

        }
        return $this->fetch();
    }

    /***
     * 标为已读
     */
    public function batchDelBanner(){
        $ids = input('param.ids');
        $data['see_time'] = date('Y-m-d H:i:s',time());
        $data['feedback_status'] = 2;
        $list = Db::table('up_feedback')->where('feedback_id',$ids)->update($data);
        if($list){
            return json(['code' => 200, 'data' =>"", 'msg' => '标为已读成功']);
        }else{
            return json(['code' => 100, 'data' => '', 'msg' => '标为已读失败']);
        }
    }

    /***
     * 查看
     */
    public function details(){
        $id = input('param.id');
        $where['a.feedback_id'] = $id;
        $list = Db::table('up_feedback')->alias('a')
            ->join('up_u_user uuu','uuu.user_id = a.user_id','left')
            ->where($where)
            ->field('a.*,uuu.user_username,uuu.user_phone')
            ->find();
        $this->assign('res',$list);
        return $this->fetch();
    }
}